import { Injectable } from "@nestjs/common";
import { InjectModel } from "@nestjs/mongoose";
import { Category } from "./interfaces/category.interface";
import { CreateCategoryDto } from "./dto/create-category.dto";
import { Model } from "mongoose";
@Injectable()
export class CategoryService {
  constructor(
    @InjectModel("Category") private readonly categoryModel: Model<Category>,
  ) {}
  async findAll(): Promise<Category[]> {
    return await this.categoryModel
      .find()
      .populate({ path: "articles", populate: { path: "author" } });
  }

  async create(createCategoryDto: CreateCategoryDto) {
    return await this.categoryModel.create(createCategoryDto);
  }
}
